package top.continew.admin.controller.qywx;

import cn.shengchao.examstar.rpc.base.PageResult;
import cn.shengchao.examstar.rpc.wecom.api.CustomerServiceGroupApi;
import cn.shengchao.examstar.rpc.wecom.req.CsUserQuery;
import cn.shengchao.examstar.rpc.wecom.req.CustomerServiceGroupPageQuery;
import cn.shengchao.examstar.rpc.wecom.req.CustomerServiceUserState;
import cn.shengchao.examstar.rpc.wecom.resp.CustomerServiceGroupDetailVo;
import cn.shengchao.examstar.rpc.wecom.resp.CustomerServiceGroupVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import top.continew.admin.req.wecom.CustomerServiceGroupRto;
import top.continew.admin.req.wecom.CustomerServiceGroupStateRto;
import top.continew.admin.req.wecom.EmployeeUserRto;
import top.continew.starter.web.model.R;

import java.util.List;

/**
 * @program: examstar-manger-api
 * @description: 客服组业务操作
 * @author: Xiong weiqiang
 * @create: 2025-04-09 15:25
 */
@Tag(name = "企微-客服组业务")
@RestController
@RequestMapping("/qywx/csGroup")
public class CustomerServiceGroupController {
    @DubboReference
    private CustomerServiceGroupApi customerServiceGroupApi;

    /**
     * 分页查询客服组列表
     * @param pageQuery
     * @return
     */
    @Operation(summary = "分页查询客服组列表", description = "分页查询客服组列表")
    @GetMapping("/pageQuery")
    PageResult<CustomerServiceGroupVo> pageQuery(CustomerServiceGroupPageQuery pageQuery) {
        return customerServiceGroupApi.queryCustomerServiceGroupPage(pageQuery);
    }

    /**
     * 客服组详情
     * @param groupId
     * @return
     */
    @Operation(summary = "客服组详情", description = "客服组详情")
    @GetMapping("/detail/{groupId}")
    R<CustomerServiceGroupDetailVo> detail(@PathVariable Long groupId) {
        CustomerServiceGroupDetailVo vo=customerServiceGroupApi.getCustomerServiceGroupDetail(groupId);
        return R.ok(vo);
    }
    /**
     * 客服成员企微号可选的列表
     * @param userQuery
     * @return
     */
    @Operation(summary = "客服成员企微号可选的列表", description = "客服成员企微号可选的列表")
    @GetMapping("/weComUserList")
    R<List<CustomerServiceUserState>> wecomUserList(CsUserQuery userQuery) {
        List<CustomerServiceUserState> list=customerServiceGroupApi.listWeComUserByQuery(userQuery);
        return R.ok(list);
    }
    /**
     * 客服组保存更新
     * @param customerServiceGroupRto
     * @return
     */
    @Operation(summary = "客服组保存更新", description = "客服组保存更新")
    @PostMapping("/save")
    R save(@RequestBody CustomerServiceGroupRto customerServiceGroupRto) {
        customerServiceGroupApi.saveCustomerServiceGroup(customerServiceGroupRto.toDto());
        return R.ok();
    }
    /**
     * 客服组改状态
     * @param customerServiceGroupStateRto
     * @return
     */
    @Operation(summary = "客服组改状态", description = "客服组改状态")
    @PostMapping("/changeStatus")
    R changeStatus(@Validated  @RequestBody CustomerServiceGroupStateRto customerServiceGroupStateRto) {
        if (customerServiceGroupStateRto.getGroupId()==0L){
            return R.fail(R.fail().getCode(), "平台客服组不能修改");
        }
        customerServiceGroupApi.changeCustomerServiceGroupState(customerServiceGroupStateRto.toDto());
        return R.ok();
    }
    /**
     * 客服组删除
     * @param groupId
     * @return
     */
    @Operation(summary = "客服组删除", description = "客服组删除")
    @PostMapping("/delete/{groupId}")
    R delete(@PathVariable Long groupId) {
        if (groupId!=null&&groupId==0L){
            return R.fail(R.fail().getCode(), "平台客服组不能修改");
        }
        customerServiceGroupApi.delCustomerServiceGroupDetail(groupId);
        return R.ok();
    }


}